#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> arr;
    vector<int> dp; // dp[i]指代以i处元素结尾的最大子数组和
    int cnt; cin >> cnt;
    for (int i = 0; i < cnt; i++) {
        int curr; cin >> curr;
        arr.push_back(curr);
    }
    int result = arr[0];
    dp.resize(cnt, 0);
    for (int i = 0; i < cnt; i++) {
        if (i == 0) { dp[i] = arr[i] > 0 ? arr[i] : 0; }
        else {
            dp[i] = dp[i - 1] >= 0 ? dp[i - 1] + arr[i] : arr[i];
        }
        if (dp[i] > result) { result = dp[i]; }
    }
    cout << result;
    return 0;
}